﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class UdfGridReportSettingDetailDA : IUdfGridReportSettingDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string CTRL_ID = "@CTRL_ID";
        private string CTRL_LABEL = "@CTRL_LABEL";
        private string CTRL_TYPE = "@CTRL_TYPE";
        private string DEFAULT_VALUE = "@DEFAULT_VALUE";
        private string IS_MUST_INPUT = "@IS_MUST_INPUT";
        private string LINE_ID = "@LINE_ID";
        private string PARAM_NAME = "@PARAM_NAME";
        private string REPORT_ID = "@REPORT_ID";
        private string SQL_CHECK_UDF_GRID_REPORT_SETTING_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@UDF_GRID_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_ONE_UDF_GRID_REPORT_SETTING_DETAIL = " DELETE FROM @_@UDF_GRID_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_UDF_GRID_REPORT_SETTING_DETAIL = " DELETE FROM @_@UDF_GRID_REPORT_SETTING_DETAIL WHERE REPORT_ID = @REPORT_ID ";
        private string SQL_INSERT_UDF_GRID_REPORT_SETTING_DETAIL = " INSERT INTO @_@UDF_GRID_REPORT_SETTING_DETAIL ( WH_ID, REPORT_ID, LINE_ID, CTRL_ID, CTRL_LABEL, CTRL_TYPE, DEFAULT_VALUE, PARAM_NAME, IS_MUST_INPUT, UDF1, UDF2, UDF3, UDF4, UDF5, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @REPORT_ID, @LINE_ID, @CTRL_ID, @CTRL_LABEL, @CTRL_TYPE, @DEFAULT_VALUE, @PARAM_NAME, @IS_MUST_INPUT, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL = " SELECT  ROWID, WH_ID, REPORT_ID, LINE_ID, CTRL_ID, CTRL_LABEL, CTRL_TYPE, DEFAULT_VALUE, PARAM_NAME, IS_MUST_INPUT, UDF1, UDF2, UDF3, UDF4, UDF5, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE  FROM  @_@UDF_GRID_REPORT_SETTING_DETAIL ";
        private string SQL_UPDATE_UDF_GRID_REPORT_SETTING_DETAIL = " UPDATE @_@UDF_GRID_REPORT_SETTING_DETAIL SET WH_ID = @WH_ID, CTRL_ID = @CTRL_ID, CTRL_LABEL = @CTRL_LABEL, CTRL_TYPE = @CTRL_TYPE, DEFAULT_VALUE = @DEFAULT_VALUE, PARAM_NAME = @PARAM_NAME, IS_MUST_INPUT = @IS_MUST_INPUT, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID  ";
        private string UDF1 = "@UDF1";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckUdfGridReportSettingDetailIDUnique(string reportID, string LineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", LineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_UDF_GRID_REPORT_SETTING_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckUdfGridReportSettingDetailIDUnique(DataBase dataBase, DbTransaction tran, string reportID, string LineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", LineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_UDF_GRID_REPORT_SETTING_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteUdfGridReportSettingDetail(List<string> reportID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                string sqlStr = this.SQL_DELETE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteUdfGridReportSettingDetail(List<string> reportID, List<string> lineID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                string sqlStr = this.SQL_DELETE_ONE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteUdfGridReportSettingDetail(DataBase dataBase, DbTransaction tran, List<string> reportID, string whLoginID)
        {
            int result = 0;
            try
            {
                string sqlStr = this.SQL_DELETE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return result;
        }

        public int DeleteUdfGridReportSettingDetail(DataBase dataBase, DbTransaction tran, List<string> reportID, List<string> lineID, string whLoginID)
        {
            int result = 0;
            try
            {
                string sqlStr = this.SQL_DELETE_ONE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
                for (int j = 0; j < reportID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllUdfGridReportSettingDetail(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllUdfGridReportSettingDetail(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public UdfGridReportSettingDetailInfo GetUdfGridReportSettingDetailByID(string reportID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", lineID) };
            UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    udfGridReportSettingDetailInfo = new UdfGridReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return udfGridReportSettingDetailInfo;
        }

        public UdfGridReportSettingDetailInfo GetUdfGridReportSettingDetailByID(DataBase dataBase, DbTransaction tran, string reportID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID AND LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID), new SqlParameter("@LINE_ID", lineID) };
            UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                udfGridReportSettingDetailInfo = new UdfGridReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return udfGridReportSettingDetailInfo;
        }

        public DataSet GetUdfGridReportSettingDetailByQueryList(List<string> sqlWhere, UdfGridReportSettingDetailQueryEntity udfgridreportsettingdetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!udfgridreportsettingdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, udfgridreportsettingdetailQuery.CurrentPage, udfgridreportsettingdetailQuery.PageSize, udfgridreportsettingdetailQuery.SortField, udfgridreportsettingdetailQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetUdfGridReportSettingDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, UdfGridReportSettingDetailQueryEntity udfgridreportsettingdetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            temp = PagingHelper.GetPagingSQL(temp, udfgridreportsettingdetailQuery.CurrentPage, udfgridreportsettingdetailQuery.PageSize, udfgridreportsettingdetailQuery.SortField, udfgridreportsettingdetailQuery.SortDirection);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<UdfGridReportSettingDetailInfo> GetUdfGridReportSettingDetailListByID(string reportID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID ORDER BY LINE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID) };
            List<UdfGridReportSettingDetailInfo> udfGridReportSettingDetailInfos = new List<UdfGridReportSettingDetailInfo>();
            UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    udfGridReportSettingDetailInfo = new UdfGridReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                    udfGridReportSettingDetailInfos.Add(udfGridReportSettingDetailInfo);
                }
            }
            return udfGridReportSettingDetailInfos;
        }

        public List<UdfGridReportSettingDetailInfo> GetUdfGridReportSettingDetailListByID(DataBase dataBase, DbTransaction tran, string reportID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID) + " WHERE REPORT_ID = @REPORT_ID ORDER BY LINE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@REPORT_ID", reportID) };
            List<UdfGridReportSettingDetailInfo> udfGridReportSettingDetailInfos = new List<UdfGridReportSettingDetailInfo>();
            UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo = null;
            using (IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    udfGridReportSettingDetailInfo = new UdfGridReportSettingDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["REPORT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["CTRL_ID"].ToString(), reader["CTRL_LABEL"].ToString(), reader["CTRL_TYPE"].ToString(), reader["DEFAULT_VALUE"].ToString(), reader["PARAM_NAME"].ToString(), reader["IS_MUST_INPUT"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                    udfGridReportSettingDetailInfos.Add(udfGridReportSettingDetailInfo);
                }
            }
            return udfGridReportSettingDetailInfos;
        }

        public int InsertUdfGridReportSettingDetail(UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                udfGridReportSettingDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_UdfGridReportSettingDetail_Parameters(udfGridReportSettingDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int InsertUdfGridReportSettingDetail(DataBase dataBase, DbTransaction tran, UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                udfGridReportSettingDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_UdfGridReportSettingDetail_Parameters(udfGridReportSettingDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_UdfGridReportSettingDetail_Parameters(UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.REPORT_ID, SqlDbType.VarChar, 30), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.CTRL_ID, SqlDbType.VarChar, 50), new SqlParameter(this.CTRL_LABEL, SqlDbType.VarChar, 100), new SqlParameter(this.CTRL_TYPE, SqlDbType.VarChar, 50), new SqlParameter(this.DEFAULT_VALUE, SqlDbType.VarChar, 200), new SqlParameter(this.PARAM_NAME, SqlDbType.VarChar, 100), new SqlParameter(this.IS_MUST_INPUT, SqlDbType.VarChar, 1), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 30), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 30) };
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.WhID))
            {
                paramArray[0].Value = udfGridReportSettingDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = udfGridReportSettingDetailInfo.ReportID;
            paramArray[2].Value = udfGridReportSettingDetailInfo.LineID;
            paramArray[3].Value = udfGridReportSettingDetailInfo.CtrlID;
            paramArray[4].Value = udfGridReportSettingDetailInfo.CtrlLabel;
            paramArray[5].Value = udfGridReportSettingDetailInfo.CtrlType;
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.DefaultValue))
            {
                paramArray[6].Value = udfGridReportSettingDetailInfo.DefaultValue;
            }
            else
            {
                paramArray[6].Value = DBNull.Value;
            }
            paramArray[7].Value = udfGridReportSettingDetailInfo.ParamName;
            paramArray[8].Value = udfGridReportSettingDetailInfo.IsMustInput;
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.Udf1))
            {
                paramArray[9].Value = udfGridReportSettingDetailInfo.Udf1;
            }
            else
            {
                paramArray[9].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.Udf2))
            {
                paramArray[10].Value = udfGridReportSettingDetailInfo.Udf2;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.Udf3))
            {
                paramArray[11].Value = udfGridReportSettingDetailInfo.Udf3;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.Udf4))
            {
                paramArray[12].Value = udfGridReportSettingDetailInfo.Udf4;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(udfGridReportSettingDetailInfo.Udf5))
            {
                paramArray[13].Value = udfGridReportSettingDetailInfo.Udf5;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            paramArray[14].Value = udfGridReportSettingDetailInfo.CreatedBy;
            paramArray[15].Value = udfGridReportSettingDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateUdfGridReportSettingDetail(UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                udfGridReportSettingDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_UdfGridReportSettingDetail_Parameters(udfGridReportSettingDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateUdfGridReportSettingDetail(DataBase dataBase, DbTransaction tran, UdfGridReportSettingDetailInfo udfGridReportSettingDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                udfGridReportSettingDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_UdfGridReportSettingDetail_Parameters(udfGridReportSettingDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_UDF_GRID_REPORT_SETTING_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

